<?
ini_set("display_errors",1);
include($_SERVER['DOCUMENT_ROOT'].'/includes/functions.inc.php');
include($_SERVER['DOCUMENT_ROOT'].'/portals/config.php');
include($_SERVER['DOCUMENT_ROOT'].'/groups/database.php');

init_session();

if (empty($_SESSION['user_id'])) {
	include($_SERVER['DOCUMENT_ROOT'].'/portals/login.inc.php');
	exit;
}

include($_SERVER['DOCUMENT_ROOT'].'/portals/header.inc.php');




$sql = array();
$sql['columns'] = 'p.*,count,substring(p.created,1,10) as created';
$sql['tables'] = array();
$sql['tables'][] = "portal p";
$sql['tables'][] = "LEFT JOIN active_cache USING (portal_id)";
$sql['wheres'] = array();

$sql['wheres'][] = "user_id = ".intval($_SESSION['user_id']);

if (!empty($_GET['public'])) {
	$sql['wheres'][] = "public = ".dbQuote($_GET['public']);
}

$sql['order'] = "portal_id DESC";



$query = sqlMakeQuery($sql);

$data = getAssoc($query);



if ($data) {
	print "Your portals...";
	print "<ul class=\"list\">";
	foreach ($data as $id => $c) {
		
		print "<li><small>{$c['created']}</small> ";
		if ($c['public'] != 'Y') {
			print "<a href=\"portal.php?id=$id\" style=\"color:red\">".hec('title')."</a>";
			print " - <b>Not Public</b>"; 
		} else {
			print "<b><a href=\"portal.php?id=$id\">".hec('title')."</a></b>";
		}
		if (is_null($c['count'])) {		
			$count = count_active($id);
		} else {
			$count = $c['count'];
		}
		print " <small>[$count images]</small>";
		
		if (!empty($_SESSION['user_id'])) {
			print " <a href=\"edit.php?id=$id\" class=\"edit\">Edit</a>";
			print " <a href=\"filters.php?id=$id\" class=\"edit\">Filters</a>";
		}
		print "</li>";
	}
	print "</ul>";
} else {
	print "<p>No Portals to show at this time. <a href=\"edit.php\">Create one</a>!</p>";
}

include($_SERVER['DOCUMENT_ROOT'].'/portals/footer.inc.php');
